Introduction

photo_data %>%
  select(pageURL) %>%
  knitr::kable()
pageURL
https://pixabay.com/photos/red-panda-panda-animal-wilderness-8372704/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-7504633/
https://pixabay.com/photos/red-panda-lesser-panda-wildlife-4366264/
https://pixabay.com/photos/red-panda-bamboo-tongue-out-mammal-1851650/
https://pixabay.com/photos/red-panda-animal-baby-branch-cute-1852860/
https://pixabay.com/photos/panda-red-panda-bear-furry-mammal-7015575/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-3508116/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-3503779/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-3508153/
https://pixabay.com/photos/red-panda-leaves-branch-outdoors-1852789/
https://pixabay.com/photos/red-panda-animal-carnivore-close-up-1851661/
https://pixabay.com/photos/red-panda-animal-mammal-1982445/
https://pixabay.com/photos/animal-red-panda-mammal-species-4418773/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-3161290/
https://pixabay.com/photos/red-panda-tree-carnivore-mammal-1852861/
https://pixabay.com/photos/red-panda-lesser-panda-animal-4211083/
https://pixabay.com/photos/red-panda-animal-cute-furry-1851590/
https://pixabay.com/photos/animal-panda-red-bear-zoo-nature-4660971/
https://pixabay.com/photos/red-panda-mammal-animal-wild-animal-1852830/
https://pixabay.com/photos/animals-red-pandas-cuddle-pair-1852823/
https://pixabay.com/photos/red-panda-panda-animal-mammal-7764725/
https://pixabay.com/photos/red-panda-panda-animal-mammal-7753226/
https://pixabay.com/photos/nature-mammal-animal-wildlife-cute-3162233/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-4546244/
https://pixabay.com/photos/red-panda-animal-lesser-panda-7530417/
https://pixabay.com/photos/red-panda-yawns-curious-1194506/
https://pixabay.com/photos/red-panda-panda-animal-mammal-1194504/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-4387000/
https://pixabay.com/photos/red-panda-bear-animal-mammal-fur-5475574/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-1721912/
https://pixabay.com/photos/red-panda-little-panda-bamboo-1182069/
https://pixabay.com/photos/illustration-red-panda-zoo-2246804/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-4404234/
https://pixabay.com/photos/red-panda-sleeping-on-branch-china-3507877/
https://pixabay.com/photos/chinese-panda-red-panda-snow-1985466/
https://pixabay.com/photos/animal-branch-cute-red-panda-1851593/
https://pixabay.com/photos/red-panda-little-panda-cute-curious-1194509/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-3740786/
https://pixabay.com/photos/adorable-animal-cute-fox-fur-1851594/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-3040830/
https://pixabay.com/photos/panda-brown-panda-little-panda-3262048/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-4129283/
https://pixabay.com/photos/little-panda-red-panda-cat-bear-3715618/
https://pixabay.com/photos/red-panda-little-panda-bamboo-1182078/
https://pixabay.com/photos/red-panda-little-panda-bamboo-1182066/

Key features of selected photos

highest_download <- max(photo_data$downloads)

Mean_view <- round(mean(photo_data$views[photo_data$view_count == "High"]),2)

download_high <- median(photo_data$downloads[photo_data$view_count == "High"])

download_low <- median(photo_data$downloads[photo_data$view_count == "Low"])

unique_tag <- photo_data %>%
  pull(tags) %>%
  unique()

mean_view_tag <- mean(photo_data$views[grep(unique_tag, photo_data$tags)])

Creativitiy

Learning reflection

Appendix

library(tidyverse)
library(jsonlite)
json_data <- fromJSON("pixabay_data.json")
pixabay_photo_data <- json_data$hits

# function required to use
# filter (), mutate(), select ()
# mutate(), create 3 new varaibles, 2 categorical variable and 1 numeric variable

selected_photos_1 <- pixabay_photo_data %>%
  slice(c(1:55)) %>% #new data frame that contains around 50 photos
  select(previewURL, pageURL, views, downloads, likes) # use select() function that include preview URL and pageURL

selected_photos_2 <- pixabay_photo_data %>%
  filter(likes >50 & views >= median(views)) %>%
  select(previewURL, pageURL, views, downloads, likes, tags) %>%
  mutate(img_pop= ifelse(likes > 100, "P", "NP")) %>%
  mutate(view_count= ifelse(views > mean(views), "High", "Low")) %>%
  mutate(num_tags= str_count(tags, ", ")+1)

write_csv(selected_photos_2, "selected_photos.csv")

#Summary values 
selected_photos_2 %>%
  group_by(likes) %>%
  summarise(mean.likes)

mean.likes<- selected_photos_2$likes %>% mean(na.rm = TRUE)

median.views <- selected_photos_2$views %>% median(na.rm =TRUE)

pop_count <- selected_photos_2 %>%
  group_by(img_pop) %>%
  summarise(num_p= n())

HL_count <- selected_photos_2 %>%
  group_by(view_count) %>%
  summarise(num_HL=n())

downloads_by_category <- selected_photos_2 %>%
  group_by(tags) %>%
  summarise(Totaldownloads = sum(downloads)/10000) %>%
  arrange()

popularity_count <- selected_photos_2 %>%
  group_by(tags) %>%
  summarise(count=n())

highest_download <- max(photo_data$downloads)


tag_popularity <- selected_photos_2 %>%
  separate_rows(tags, sep = ", ") %>%
  mutate(tags = trimws(tags)) #split the individual words and create new column for each word in dataest

word_popularity <- tag_popularity %>%
  group_by(tags, img_pop) %>%
  summarise(count= n() > 5) #separte values for the count of popularity with higher than 5

img_urls <- selected_photos_2$previewURL %>% na.omit()

image_read(img_urls) %>%
  image_join() %>%
  image_scale(400) %>%
  image_animate(fps=1) %>%
  image_write("my_photos.gif")

#Creative R code


view_count_table <- table(photo_data$view_count)
pie(view_count_table, labels = paste(names(view_count_table), ": ", view_count_table), main = "Distribution of View count")

sorted <- photo_data%>%
  arrange(desc(views))

top3 <- sorted %>%
  group_by(img_pop) %>%
  slice(1:3)

observ_img <-ggplot(top3, aes(x= views, y= likes, color= img_pop)) +
  geom_point(size=3) +
  facet_wrap(~img_pop, ncol=1) +
  labs(title= "Top 3 observation by img popularity",
       x = "views",
       y= "likes",
       color = "Img popularity") +
  theme_minimal()